package com.mba.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Adapter;
import android.widget.LinearLayout;
import android.widget.ScrollView;

/**
 * @author Jeffrey Shi
 * QQ 362116120
 * MAIL to shijunfan@163.com
 */
public class JListView extends ScrollView{
	private LinearLayout layout;
	private Adapter adapter;
	public JListView(Context context) {
		super(context);
		init(context);
	}

	public JListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}
	private void init(Context context) {
		layout=new LinearLayout(context);
		layout.setOrientation(LinearLayout.VERTICAL);
		layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		addView(layout);
	}
	
	public void setAdapter(Adapter adapter) {
		this.adapter=adapter;
		refresh();
	}
	
	public int getViewCount(){
		return layout.getChildCount();
	}
	public View getChildView(int index){
		return layout.getChildAt(index);
	}
	public void refresh(){
		layout.removeAllViews();
		for(int i=0;i<adapter.getCount();i++){
			View v=adapter.getView(i, null, null);
			layout.addView(v);
		}
	}
}
